#include <stdio.h>
#include <stdlib.h>
#include <String.h>
#define VMAXSIZE 10
#define DMAXSIZE 20
#define OK 1
int i = 0;

typedef int Status;
typedef char ElemType;
typedef struct 
{
    char *V;
    char *D;
    int lengthV;
    int lengthD;
}HS;

Status InitHS(HS H[],int n);
Status InputHS(HS H[],int n);
Status IndexBF(HS H[],char VD[],int n);
Status Call(HS H[],int n);

Status main()
{
    int n;
    scanf("%d",&n);
    HS H[n];
    InitHS(H,n);
    InputHS(H,n);
    Call(H,n);
    //IndexBF(H,n);
    return 0;
}

Status InitHS(HS H[],int n)
{
    for(i=0;i<n;i++)
    {
        H[i].V = (char*)malloc(sizeof(char)*VMAXSIZE);
        H[i].D = (char*)malloc(sizeof(char)*DMAXSIZE);
    }
    return OK;   
}

Status InputHS(HS H[],int n)
{
    for(i=0;i<n;i++)
    {
       scanf("%s%s",H[i].V,H[i].D);
       H[i].lengthV = strlen(H[i].V);
       H[i].lengthD = strlen(H[i].D);
    }
    return OK;
}

Status IndexBF(HS H[],char VD[],int n)
{
    int j = 0,k = 0;
        while (k<H[i].lengthD && j<H[i].lengthV)
        {
            if(H[i].D[k] == VD[i])
            {
                 ++k;++j;
            }
            else
            {
                k = k-j+1;j = 0;
            }
        }
        if(j==H[i].lengthV)
        {
             printf("YES\n");
        }
        else
        {
             printf("NO\n");  
        }
    return 0;    
}

Status Call(HS H[],int n)
{
    char J[2*VMAXSIZE],L[VMAXSIZE];
    int y=0,flg=0,t=0;
    for(i=0;i<n;i++)
    {
        strcpy(J,H[i].V);
        strcat(J,H[i].V);
        for(y=0,flg=0;y<2*(H[i].lengthV);y++,flg++)
        {
            L[flg] = J[y];
            if(flg+1==H[i].lengthV)
            {
                ++t;
                IndexBF(H,L,n);
                flg=t-1;
                if(t+1==H[i].lengthV)
                break;
            }
        }
    }
}